package com.hopu.iocdemo1;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ComputerTest {

    public static void main(String[] args) throws IllegalAccessException, NoSuchFieldException, InstantiationException {
//        Computer computer = new Computer();
//        computer.start();
//        ComputerFactory computerFactory = new ComputerFactory();
//        Computer computer = computerFactory.createComputer();
//        computer.start();
        //创建基于XML配置的容器
        ClassPathXmlApplicationContext cxt =
                new ClassPathXmlApplicationContext("spring-ioc.xml");
        //获得对象
//        Computer computer = (Computer) cxt.getBean("computer");
        Computer computer = cxt.getBean(Computer.class);
        Computer computer2 = cxt.getBean(Computer.class);
        System.out.println(computer == computer2);
        computer.start();
    }
}
